/*
 *  Bullet.cpp
 *  Rempart
 *
 *  Created by julien BONACHERA on 30/05/11.
 *  Copyright 2011 __MyCompanyName__. All rights reserved.
 *
 */

#include "Bullet.h"

Bullet::Bullet(){
	this->SetImage(*RessourcesManager::getDefaultBulletSurface());
}



Bullet::Bullet(const sf::Vector2<float>& target,const sf::Vector2<float>& position, bool isBoatBullet){
	
	this->localClock = new sf::Clock();
	this->coeff = new sf::Vector2<float>();
	
	this->outOfMap = false;
	if (isBoatBullet) {
		this->SetImage(*RessourcesManager::getBoatBulletSurface());
	}
	else {
		this->SetImage(*RessourcesManager::getDefaultBulletSurface());
	}

	
	this->SetPosition(position.x,position.y);
	float yLength=(target.x-  position.x);
	float xLength=(target.y- position.y);
	float length = sqrt(pow(yLength, 2)+pow(xLength, 2));
	
	this->coeff->x = yLength/(length*0.004);
	this->coeff->y = xLength/(length*0.004);

}


Bullet::~Bullet(){
	delete this->localClock;
	delete this->coeff;
}

void Bullet::move(){
	float time = this->localClock->GetElapsedTime();
	this->Move(this->coeff->x*time,this->coeff->y*time);
	this->localClock->Reset();
}

bool Bullet::isOutOfMap(){
	return this->outOfMap;
}
void Bullet::setOufOfMap(){
	this->outOfMap = true;
}

sf::Vector2<int>Bullet::getMapPosition(){
	
	return sf::Vector2<int>(this->GetPosition().x/MapElement::getWidth(),this->GetPosition().y/MapElement::getHeigth());
	
}
